package com.ruoyi.report.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.report.domain.ReportShowtableColumn;
import com.ruoyi.report.mapper.ReportShowtableColumnMapper;
import com.ruoyi.report.service.IReportShowtableColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  报告展示列维护Service业务层处理
 * 
 * @author wry
 * @date 2023-06-20
 */
@Service
public class ReportShowtableColumnServiceImpl implements IReportShowtableColumnService 
{
    @Autowired
    private ReportShowtableColumnMapper reportShowtableColumnMapper;

    /**
     * 查询 报告展示列维护
     * 
     * @param showColumnId  报告展示列维护主键
     * @return  报告展示列维护
     */
    @Override
    public ReportShowtableColumn selectReportShowtableColumnByColumnId(Long showColumnId)
    {
        return reportShowtableColumnMapper.selectReportShowtableColumnByShowColumnId(showColumnId);
    }

    /**
     * 查询 报告展示列维护列表
     * 
     * @param reportShowtableColumn  报告展示列维护
     * @return  报告展示列维护
     */
    @Override
    public List<ReportShowtableColumn> selectReportShowtableColumnList(ReportShowtableColumn reportShowtableColumn)
    {
        return reportShowtableColumnMapper.selectReportShowtableColumnList(reportShowtableColumn);
    }

    /**
     * 新增 报告展示列维护
     * 
     * @param reportShowtableColumn  报告展示列维护
     * @return 结果
     */
    @Override
    public int insertReportShowtableColumn(ReportShowtableColumn reportShowtableColumn)
    {
        reportShowtableColumn.setCreateTime(DateUtils.getNowDate());
        return reportShowtableColumnMapper.insertReportShowtableColumn(reportShowtableColumn);
    }

    /**
     * 修改 报告展示列维护
     * 
     * @param reportShowtableColumn  报告展示列维护
     * @return 结果
     */
    @Override
    public int updateReportShowtableColumn(ReportShowtableColumn reportShowtableColumn)
    {
        reportShowtableColumn.setUpdateTime(DateUtils.getNowDate());
        reportShowtableColumnMapper.updateTableColumnByName(reportShowtableColumn.getTableName(), reportShowtableColumn.getTableName());
        return reportShowtableColumnMapper.updateReportShowtableColumn(reportShowtableColumn);
    }

    /**
     * 批量删除 报告展示列维护
     * 
     * @param showColumnIds 需要删除的 报告展示列维护主键
     * @return 结果
     */
    @Override
    public int deleteReportShowtableColumnByColumnIds(Long[] showColumnIds)
    {
        return reportShowtableColumnMapper.deleteReportShowtableColumnByShowColumnIds(showColumnIds);
    }

    /**
     * 删除 报告展示列维护信息
     * 
     * @param showColumnId  报告展示列维护主键
     * @return 结果
     */
    @Override
    public int deleteReportShowtableColumnByColumnId(Long showColumnId)
    {
        return reportShowtableColumnMapper.deleteReportShowtableColumnByShowColumnId(showColumnId);
    }

    /**
     * 校验字典类型称是否唯一
     *
     * @param reportShowtableColumn 表格数据
     * @return 结果
     */
    @Override
    public boolean checkColumnSortUnique(ReportShowtableColumn reportShowtableColumn)
    {
        Long columnId = StringUtils.isNull(reportShowtableColumn.getShowColumnId()) ? -1L : reportShowtableColumn.getShowColumnId();
        ReportShowtableColumn searchColumn=new ReportShowtableColumn();
        searchColumn.setTableName(reportShowtableColumn.getTableName());
        searchColumn.setColumnSort(reportShowtableColumn.getColumnSort());
        searchColumn.setTableId(reportShowtableColumn.getTableId());
        List<ReportShowtableColumn> columnList=reportShowtableColumnMapper.selectReportShowtableColumnList(searchColumn);
        if (columnList.size()>0 && columnList.get(0).getShowColumnId().longValue() != columnId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
